<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>常用数据集 Datasets - Keras 中文文档</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
  
  <script>
    // Current page data
    var mkdocs_page_name = "\u5e38\u7528\u6570\u636e\u96c6 Datasets";
    var mkdocs_page_input_path = "datasets.md";
    var mkdocs_page_url = "/zh/datasets/";
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
  <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-61785484-1', 'keras.io');
      ga('send', 'pageview');
  </script>
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> Keras 中文文档</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
	<ul class="current">
	  
          
            <li class="toctree-l1">
		
    <a class="" href="..">主页</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../why-use-keras/">为什么选择 Keras?</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">快速开始</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../getting-started/sequential-model-guide/">Sequential 顺序模型指引</a>
                </li>
                <li class="">
                    
    <a class="" href="../getting-started/functional-api-guide/">函数式 API 指引</a>
                </li>
                <li class="">
                    
    <a class="" href="../getting-started/faq/">FAQ 常见问题解答</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">模型</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../models/about-keras-models/">关于 Keras 模型</a>
                </li>
                <li class="">
                    
    <a class="" href="../models/sequential/">Sequential 顺序模型 API</a>
                </li>
                <li class="">
                    
    <a class="" href="../models/model/">函数式 API</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Layers</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../layers/about-keras-layers/">关于 Keras 网络层</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/core/">核心网络层</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/convolutional/">卷积层 Convolutional</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/pooling/">池化层 Pooling</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/local/">局部连接层 Locally-connected</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/recurrent/">循环层 Recurrent</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/embeddings/">嵌入层 Embedding</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/merge/">融合层 Merge</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/advanced-activations/">高级激活层 Advanced Activations</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/normalization/">标准化层 Normalization</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/noise/">噪声层 Noise</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/wrappers/">层封装器 wrappers</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/writing-your-own-keras-layers/">编写你自己的层</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">数据预处理</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../preprocessing/sequence/">序列预处理</a>
                </li>
                <li class="">
                    
    <a class="" href="../preprocessing/text/">文本预处理</a>
                </li>
                <li class="">
                    
    <a class="" href="../preprocessing/image/">图像预处理</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../losses/">损失函数 Losses</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../metrics/">评估标准 Metrics</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../optimizers/">优化器 Optimizers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../activations/">激活函数 Activations</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../callbacks/">回调函数 Callbacks</a>
	    </li>
          
            <li class="toctree-l1 current">
		
    <a class="current" href="./">常用数据集 Datasets</a>
    <ul class="subnav">
            
    <li class="toctree-l2"><a href="#_1">数据集</a></li>
    
        <ul>
        
            <li><a class="toctree-l3" href="#cifar10">CIFAR10 小图像分类数据集</a></li>
        
            <li><a class="toctree-l3" href="#cifar100">CIFAR100 小图像分类数据集</a></li>
        
            <li><a class="toctree-l3" href="#imdb">IMDB 电影评论情感分类数据集</a></li>
        
            <li><a class="toctree-l3" href="#_5">路透社新闻主题分类</a></li>
        
            <li><a class="toctree-l3" href="#mnist">MNIST 手写字符数据集</a></li>
        
            <li><a class="toctree-l3" href="#fashion-mnist">Fashion-MNIST 时尚物品数据集</a></li>
        
            <li><a class="toctree-l3" href="#boston">Boston 房价回归数据集</a></li>
        
        </ul>
    

    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../applications/">应用 Applications</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../backend/">后端 Backend</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../initializers/">初始化 Initializers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../regularizers/">正则化 Regularizers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../constraints/">约束 Constraints</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../visualization/">可视化 Visualization</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../scikit-learn-api/">Scikit-learn API</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../utils/">工具</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../contributing/">贡献</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">经典样例</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../examples/addition_rnn/">Addition RNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/babi_rnn/">Baby RNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/babi_memnn/">Baby MemNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_cnn/">CIFAR-10 CNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_cnn_capsule/">CIFAR-10 CNN-Capsule</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_cnn_tfaugment2d/">CIFAR-10 CNN with augmentation (TF)</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_resnet/">CIFAR-10 ResNet</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/conv_filter_visualization/">Convolution filter visualization</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/image_ocr/">Image OCR</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/imdb_bidirectional_lstm/">Bidirectional LSTM</a>
                </li>
    </ul>
	    </li>
          
        </ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Keras 中文文档</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>常用数据集 Datasets</li>
    <li class="wy-breadcrumbs-aside">
      
        <a href="https://github.com/keras-team/keras-docs-zh/edit/master/docs/datasets.md"
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="_1">数据集</h1>
<h2 id="cifar10">CIFAR10 小图像分类数据集</h2>
<p>50,000 张 32x32 彩色训练图像数据，以及 10,000 张测试图像数据，总共分为 10 个类别。</p>
<h3 id="_2">用法：</h3>
<pre><code class="python">from keras.datasets import cifar10

(x_train, y_train), (x_test, y_test) = cifar10.load_data()
</code></pre>

<ul>
<li><strong>返回：</strong></li>
<li>2 个元组：<ul>
<li><strong>x_train, x_test</strong>: uint8 数组表示的 RGB 图像数据，尺寸为 (num_samples, 3, 32, 32) 或 (num_samples, 32, 32, 3)，基于 <code>image_data_format</code> 后端设定的 <code>channels_first</code> 或 <code>channels_last</code>。</li>
<li><strong>y_train, y_test</strong>: uint8 数组表示的类别标签（范围在 0-9 之间的整数），尺寸为 (num_samples,)。</li>
</ul>
</li>
</ul>
<hr />
<h2 id="cifar100">CIFAR100 小图像分类数据集</h2>
<p>50,000 张 32x32 彩色训练图像数据，以及 10,000 张测试图像数据，总共分为 100 个类别。</p>
<h3 id="_3">用法：</h3>
<pre><code class="python">from keras.datasets import cifar100

(x_train, y_train), (x_test, y_test) = cifar100.load_data(label_mode='fine')
</code></pre>

<ul>
<li>
<p><strong>返回：</strong></p>
<ul>
<li>2 个元组：<ul>
<li><strong>x_train, x_test</strong>: uint8 数组表示的 RGB 图像数据，尺寸为 (num_samples, 3, 32, 32) 或 (num_samples, 32, 32, 3)，基于 <code>image_data_format</code> 后端设定的 <code>channels_first</code> 或 <code>channels_last</code>。</li>
<li><strong>y_train, y_test</strong>: uint8 数组表示的类别标签，尺寸为 (num_samples,)。</li>
</ul>
</li>
</ul>
</li>
<li>
<p><strong>参数：</strong></p>
<ul>
<li><strong>label_mode</strong>: "fine" 或者 "coarse"</li>
</ul>
</li>
</ul>
<hr />
<h2 id="imdb">IMDB 电影评论情感分类数据集</h2>
<p>数据集来自 IMDB 的 25,000 条电影评论，以情绪（正面/负面）标记。评论已经过预处理，并编码为词索引（整数）的<a href="../preprocessing/sequence/">序列</a>表示。为了方便起见，将词按数据集中出现的频率进行索引，例如整数 3 编码数据中第三个最频繁的词。这允许快速筛选操作，例如：「只考虑前 10,000 个最常用的词，但排除前 20 个最常见的词」。</p>
<p>作为惯例，0 不代表特定的单词，而是被用于编码任何未知单词。</p>
<h3 id="_4">用法</h3>
<pre><code class="python">from keras.datasets import imdb

(x_train, y_train), (x_test, y_test) = imdb.load_data(path=&quot;imdb.npz&quot;,
                                                      num_words=None,
                                                      skip_top=0,
                                                      maxlen=None,
                                                      seed=113,
                                                      start_char=1,
                                                      oov_char=2,
                                                      index_from=3)
</code></pre>

<ul>
<li>
<p><strong>返回：</strong></p>
<ul>
<li>2 个元组：</li>
<li><strong>x_train, x_test</strong>: 序列的列表，即词索引的列表。如果指定了 <code>num_words</code> 参数，则可能的最大索引值是 <code>num_words-1</code>。如果指定了 <code>maxlen</code> 参数，则可能的最大序列长度为 <code>maxlen</code>。 </li>
<li><strong>y_train, y_test</strong>: 整数标签列表 (1 或 0)。</li>
</ul>
</li>
<li>
<p><strong>参数:</strong></p>
<ul>
<li><strong>path</strong>: 如果你本地没有该数据集 (在 <code>'~/.keras/datasets/' + path</code>)，它将被下载到此目录。</li>
<li><strong>num_words</strong>: 整数或 None。要考虑的最常用的词语。任何不太频繁的词将在序列数据中显示为 <code>oov_char</code> 值。</li>
<li><strong>skip_top</strong>: 整数。要忽略的最常见的单词（它们将在序列数据中显示为 <code>oov_char</code> 值）。</li>
<li><strong>maxlen</strong>: 整数。最大序列长度。 任何更长的序列都将被截断。</li>
<li><strong>seed</strong>: 整数。用于可重现数据混洗的种子。</li>
<li><strong>start_char</strong>: 整数。序列的开始将用这个字符标记。设置为 1，因为 0 通常作为填充字符。</li>
<li><strong>oov_char</strong>: 整数。由于 <code>num_words</code> 或 <code>skip_top</code> 限制而被删除的单词将被替换为此字符。</li>
<li><strong>index_from</strong>: 整数。使用此数以上更高的索引值实际词汇索引的开始。</li>
</ul>
</li>
</ul>
<hr />
<h2 id="_5">路透社新闻主题分类</h2>
<p>数据集来源于路透社的 11,228 条新闻文本，总共分为 46 个主题。与 IMDB 数据集一样，每条新闻都被编码为一个词索引的序列（相同的约定）。</p>
<h3 id="_6">用法：</h3>
<pre><code class="python">from keras.datasets import reuters

(x_train, y_train), (x_test, y_test) = reuters.load_data(path=&quot;reuters.npz&quot;,
                                                         num_words=None,
                                                         skip_top=0,
                                                         maxlen=None,
                                                         test_split=0.2,
                                                         seed=113,
                                                         start_char=1,
                                                         oov_char=2,
                                                         index_from=3)
</code></pre>

<p>规格与 IMDB 数据集的规格相同，但增加了：</p>
<ul>
<li><strong>test_split</strong>: 浮点型。用作测试集的数据比例。</li>
</ul>
<p>该数据集还提供了用于编码序列的词索引：</p>
<pre><code class="python">word_index = reuters.get_word_index(path=&quot;reuters_word_index.json&quot;)
</code></pre>

<ul>
<li>
<p><strong>返回：</strong> 一个字典，其中键是单词（字符串），值是索引（整数）。 例如，<code>word_index["giraffe"]</code> 可能会返回 <code>1234</code>。</p>
</li>
<li>
<p><strong>参数：</strong></p>
<ul>
<li><strong>path</strong>: 如果在本地没有索引文件 (at <code>'~/.keras/datasets/' + path</code>), 它将被下载到该目录。</li>
</ul>
</li>
</ul>
<hr />
<h2 id="mnist">MNIST 手写字符数据集</h2>
<p>训练集为 60,000 张 28x28 像素灰度图像，测试集为 10,000 同规格图像，总共 10 类数字标签。</p>
<h3 id="_7">用法：</h3>
<pre><code class="python">from keras.datasets import mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
</code></pre>

<ul>
<li>
<p><strong>返回：</strong></p>
<ul>
<li>2 个元组：<ul>
<li><strong>x_train, x_test</strong>: uint8 数组表示的灰度图像，尺寸为 (num_samples, 28, 28)。</li>
<li><strong>y_train, y_test</strong>: uint8 数组表示的数字标签（范围在 0-9 之间的整数），尺寸为 (num_samples,)。</li>
</ul>
</li>
</ul>
</li>
<li>
<p><strong>参数：</strong></p>
<ul>
<li><strong>path</strong>: 如果在本地没有索引文件 (at <code>'~/.keras/datasets/' + path</code>), 它将被下载到该目录。</li>
</ul>
</li>
</ul>
<hr />
<h2 id="fashion-mnist">Fashion-MNIST 时尚物品数据集</h2>
<p>训练集为 60,000 张 28x28 像素灰度图像，测试集为 10,000 同规格图像，总共 10 类时尚物品标签。该数据集可以用作 MNIST 的直接替代品。类别标签是：</p>
<table>
<thead>
<tr>
<th>类别</th>
<th>描述</th>
<th>中文</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>T-shirt/top</td>
<td>T恤/上衣</td>
</tr>
<tr>
<td>1</td>
<td>Trouser</td>
<td>裤子</td>
</tr>
<tr>
<td>2</td>
<td>Pullover</td>
<td>套头衫</td>
</tr>
<tr>
<td>3</td>
<td>Dress</td>
<td>连衣裙</td>
</tr>
<tr>
<td>4</td>
<td>Coat</td>
<td>外套</td>
</tr>
<tr>
<td>5</td>
<td>Sandal</td>
<td>凉鞋</td>
</tr>
<tr>
<td>6</td>
<td>Shirt</td>
<td>衬衫</td>
</tr>
<tr>
<td>7</td>
<td>Sneaker</td>
<td>运动鞋</td>
</tr>
<tr>
<td>8</td>
<td>Bag</td>
<td>背包</td>
</tr>
<tr>
<td>9</td>
<td>Ankle boot</td>
<td>短靴</td>
</tr>
</tbody>
</table>
<h3 id="_8">用法：</h3>
<pre><code class="python">from keras.datasets import fashion_mnist

(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
</code></pre>

<ul>
<li><strong>返回：</strong><ul>
<li>2 个元组：<ul>
<li><strong>x_train, x_test</strong>: uint8 数组表示的灰度图像，尺寸为 (num_samples, 28, 28)。</li>
<li><strong>y_train, y_test</strong>: uint8 数组表示的数字标签（范围在 0-9 之间的整数），尺寸为 (num_samples,)。</li>
</ul>
</li>
</ul>
</li>
</ul>
<hr />
<h2 id="boston">Boston 房价回归数据集</h2>
<p>数据集来自卡内基梅隆大学维护的 StatLib 库。</p>
<p>样本包含 1970 年代的在波士顿郊区不同位置的房屋信息，总共有 13 种房屋属性。
目标值是一个位置的房屋的中值（单位：k$）。</p>
<h3 id="_9">用法：</h3>
<pre><code class="python">from keras.datasets import boston_housing

(x_train, y_train), (x_test, y_test) = boston_housing.load_data()
</code></pre>

<ul>
<li>
<p><strong>参数：</strong></p>
<ul>
<li><strong>path</strong>: 缓存本地数据集的位置
(相对路径 ~/.keras/datasets)。</li>
<li><strong>seed</strong>: 在计算测试分割之前对数据进行混洗的随机种子。</li>
<li><strong>test_split</strong>: 需要保留作为测试数据的比例。</li>
</ul>
</li>
<li>
<p><strong>返回：</strong>
  Numpy 数组的元组: <code>(x_train, y_train), (x_test, y_test)</code>。</p>
</li>
</ul>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../applications/" class="btn btn-neutral float-right" title="应用 Applications">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../callbacks/" class="btn btn-neutral" title="回调函数 Callbacks"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="https://github.com/keras-team/keras-docs-zh/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../callbacks/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../applications/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>

</body>
</html>
